#include "lmaster.h"
#include "ui_lmaster.h"
extern void set_setting(QString,QString);

lmaster::lmaster(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::lmaster)
{
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(saveClick()));
}

lmaster::~lmaster()
{
    delete ui;
}

void lmaster::saveClick(){
        QString par="";
    switch(ui->comboBox->currentIndex()){
    case 0:
        par="Title";
        break;
    case 1:
        par="Artist";
        break;
    case 2:
        par="Album";
        break;
    case 3:
        par="Genre";
       break;
    }


QString currentQuery="SELECT * FROM tracks WHERE `"+par+"` LIKE '%"+ui->comboBox_2->currentText()+"%' ";

switch (ui->comboBox_3->currentIndex()){
case 0:break; // no action
case 1:currentQuery+="ORDER by RANDOM()";break; // random
case 2:currentQuery+="ORDER by `year` asc";break;
case 3:currentQuery+="ORDER by `year` desc";break;
}

set_setting("query",currentQuery);

this->accept();
this->close();
}
